package MyBlockingQueue;

public class demo1 {
    public static void main(String[] args) throws InterruptedException {
        MyArrayBlockingQueue queue = new MyArrayBlockingQueue(1);

        Thread thread = new Thread(()->{
           while (true){
               try {
                   queue.put("放入小车车");
               } catch (InterruptedException e) {
                   throw new RuntimeException(e);
               }
           }
        },"存放人物1号");

        Thread thread1 = new Thread(()->{
            while (true){
                try {
                    queue.put("放入电脑");
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        },"存放任务2号");

        Thread thread2 = new Thread(()->{
            while (true){
                try {
                    queue.take();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        },"取出人物1号");

        Thread thread3 = new Thread(()->{
           while (true){
               try {
                   queue.take();
               } catch (InterruptedException e) {
                   throw new RuntimeException(e);
               }
           }
        },"取出人物2号");

        thread.start();
        thread1.start();
        thread2.start();
        thread3.start();


    }
}
